$().ready(function () {
    $("#loginForm").validate({
//                errorLabelContainer: $("#error"),
        submitHandler: function (form) {
            // $("#password").val($.md5($("#password").val()));
            form.submit();
        },
        rules: {
            username: {
                required: true,
                minlength: 5
            },
            password: {
                required: true,
                minlength: 6
            },
            verify_pwd: {
                required: true,
                remote:{
                    url:"/vrify/check.json",
                    type: "post",
                    data:{
                        verify_pwd:function () {
                            return $("#verify_pwd").val();
                        }
                    }
                }
            }
        },
        messages: {
            username: {
                required: "请输入用户名",
                minlength: "用户名长度不能小于5个字符"
            },
            password: {
                required: "请输入密码",
                minlength: "密码长度不能小于6个字符"
            },
            verify_pwd: {
                required:"请输入验证码",
                remote: "验证码错误"
            }
        },
        errorClass: "error",
        success: 'valid',
        showErrors: function (map, list) {
            this.currentElements.removeAttr("title").removeClass("ui-state-error");
            //处理校验成功的元素的tip(销毁tooltip)
            var succList = this.successList;
            $.each(succList, function () {
                if ($(this).is(':ui-tooltip')) {
                    $(this).tooltip("destroy");
                    $(this).removeAttr("title");
                }
            })
            //校验错误tooltip提示
            $.each(list, function (index, error) {
                $(error.element).attr("title", error.message).addClass("ui-state-error");
                $(error.element).tooltip({
                    items: error.element,
                    content: error.message,
                    effect: "fade",
                    opacity: 0.5,
                    position: {my: "left top", at: "right top"}
                });
                $(error.element).tooltip("open");
                window.setTimeout(function () {
                    if ($(error.element).is(':ui-tooltip')) {
                        $(error.element).tooltip("close");
                    }
                }, 2000);
            });
        }
    });
})